<?php
/**
 * Created by PhpStorm.
 * User: win10
 * Date: 2017/12/27
 * Time: 18:11
 */
namespace common\services;

use Yii;
use common\models\BaseModels;
use common\models\kaoguobao\User;

class UserService{

    /**
     * 获取用户信息
     * @param $userId
     * @param $key
     * @return array|null|\yii\db\ActiveRecord
     */
    public static function userList($userId,$key)
    {
        $result = User::find()->where(['id' => $userId])->andWhere(['key' => $key])->limit(1)->asArray()->one();
        if(empty($result)){
            return [];
        }
        return $result;
    }

    /**
     * 根据微信d返回用户id
     * @param $wechatId
     * @return array|null|\yii\db\ActiveRecord
     */
    public static function userData($wechatId)
    {
        $data = User::find()->where(['wechat_id' => $wechatId])->limit(1)->one();
        if(!empty($data)){
            return $data->id;
        }
        return false;
    }
}